package com.weixin.paleituo.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.ExpressActivity;
import com.weixin.paleituo.activity.GoodsStoreActivity;
import com.weixin.paleituo.activity.OrderDetailsActivity;
import com.weixin.paleituo.annotation.OrderStatusType;
import com.weixin.paleituo.base.BaseOrderRecycleAdapter;
import com.weixin.paleituo.bean.GoodsListBean;
import com.weixin.paleituo.bean.StoreListBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.eventbus.OtherOrderEvent;
import com.weixin.paleituo.util.LogUtils;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.MyHorizontalScrollView;
import com.weixin.paleituo.view.TipsDialog;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Author yichao
 * Time  2018/4/7 17:51
 * Dest  待收货
 */

public class AwaitRecingOrderRecycleAdapter extends BaseOrderRecycleAdapter {


    public AwaitRecingOrderRecycleAdapter(Context context, List<StoreListBean> storeListBeans) {
        super(context, storeListBeans);

    }

    @Override
    protected void setNoCustomAwaitReceingData(NoCustomAwaitReceingViewHolder noCustomAwaitReceingViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {

        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            noCustomAwaitReceingViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.shushe_logo);
            noCustomAwaitReceingViewHolder.mTvStoreNameItemOrderHead.setText("舒社");
            noCustomAwaitReceingViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            noCustomAwaitReceingViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            noCustomAwaitReceingViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.store_cart);
            noCustomAwaitReceingViewHolder.mTvStoreNameItemOrderHead.setText(storeListBean.getStoreName());
            noCustomAwaitReceingViewHolder.mLlStorerootItemOrderHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }
        String acceptStation = storeListBean.getAcceptStation();
        String acceptTime = storeListBean.getAcceptTime();
        String orderDetailId = storeListBean.getOrderDetailId();

        if (!StringUtils.isEmpty(acceptStation)&&!StringUtils.isEmpty(acceptTime)&&!StringUtils.isEmpty(orderDetailId)) {
            noCustomAwaitReceingViewHolder.mRlExpressinfoNocustomAwaitReceving.setVisibility(View.VISIBLE);
            noCustomAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setVisibility(View.VISIBLE);
        }else {
            noCustomAwaitReceingViewHolder.mRlExpressinfoNocustomAwaitReceving.setVisibility(View.GONE);
            noCustomAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setVisibility(View.INVISIBLE);
        }
        if (storeListBean.getOrderStatus()== OrderStatusType.WAIT_RECEIVING){
            noCustomAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待发货");
            noCustomAwaitReceingViewHolder.mRlNocustomAwaitReceving.setVisibility(View.GONE);


        }else {
            noCustomAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待收货");
            noCustomAwaitReceingViewHolder.mRlNocustomAwaitReceving.setVisibility(View.VISIBLE);
        }
         noCustomAwaitReceingViewHolder.mTvExpresstitleNocustomAwaitReceving.setText(""+acceptStation);
                noCustomAwaitReceingViewHolder.mTvExpressTimeNocustomAwaitReceving.setText(""+acceptTime);

        HorizontalScrollViewGoodsItemAdapter horizontalScrollViewGoodsItemAdapter=new HorizontalScrollViewGoodsItemAdapter(mContext, (ArrayList<GoodsListBean>) goodsList);

        noCustomAwaitReceingViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.initDatas(horizontalScrollViewGoodsItemAdapter);
     //   noCustomAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待收货");
        noCustomAwaitReceingViewHolder.mTvGoodsnumberNocustomAwaitReceving.setText("共" + storeListBean.getNum() + "件商品  实付款:");
        noCustomAwaitReceingViewHolder.mTvAwaitpayforNocustomAwaitReceving.setText("￥" + UIUtils.getMoney( storeListBean.getActualPrice()));
        noCustomAwaitReceingViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.setOnItemClickListener(new MyHorizontalScrollView.OnItemClickListener() {
            @Override
            public void onClick(View view, int pos) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);
            }
        });
        noCustomAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看物流
                LogUtils.i(TAG,"查看物流");


                ExpressActivity.startActivity(mContext,storeListBean.getOrderDetailId());
            }
        });

        /**确定收货*/
        noCustomAwaitReceingViewHolder.mTvSurerecevingNocustomAwaitReceving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              //
               // ToastUtils.makeText("确定收货");
                LogUtils.i(TAG,"确定收货");

                showGotGoodsDialog(position,"您是否已收到该订单商品？","未收货","已收货", Contans.SURE_ACCEPT_GOODS_TYPE);

            }
        });
        noCustomAwaitReceingViewHolder.mLlNocustomRightLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(),null);
                mContext.startActivity(intent);
            }
        });
    }



private TipsDialog mTipsDialog;
    /**
     * 弹窗
     * @param position
     * @param content
     * @param left
     * @param right
     */
    private void showGotGoodsDialog(final int position, final String content, String left , String right, final int type) {

        mTipsDialog = new TipsDialog.Builder(mContext)
                .setCancelClickListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        mTipsDialog.dismiss();
                    }
                })
                .setContentView(content)
                .setLeftButton(left, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();
                    }
                })
                .setRightButton(right, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();

                        EventBus.getDefault().post(new OtherOrderEvent(position,type));


                    }
                })
                .build();

        mTipsDialog.show();
    }





    @Override
    protected void setCustomAwaitReceingData(CustomAwaitReceingViewHolder customAwaitReceingViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {
        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            customAwaitReceingViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.shushe_logo);
            customAwaitReceingViewHolder.mTvStoreNameItemOrderHead.setText("舒社");
            customAwaitReceingViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            customAwaitReceingViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            customAwaitReceingViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.store_cart);
            customAwaitReceingViewHolder.mTvStoreNameItemOrderHead.setText(storeListBean.getStoreName());
            customAwaitReceingViewHolder.mLlStorerootItemOrderHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }
        String acceptStation = storeListBean.getAcceptStation();
        String acceptTime = storeListBean.getAcceptTime();
        String orderDetailId = storeListBean.getOrderDetailId();

        if (!StringUtils.isEmpty(acceptStation)&&!StringUtils.isEmpty(acceptTime)&&!StringUtils.isEmpty(orderDetailId)) {
            customAwaitReceingViewHolder.mRlExpressinfoCustomAwaitReceving.setVisibility(View.VISIBLE);
            customAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setVisibility(View.VISIBLE);
        }else {
            customAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setVisibility(View.INVISIBLE);
            customAwaitReceingViewHolder.mRlExpressinfoCustomAwaitReceving.setVisibility(View.GONE);
        }

        if (storeListBean.getOrderStatus()== OrderStatusType.WAIT_RECEIVING){
            customAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待发货");

            customAwaitReceingViewHolder.mRlFootCustomAwaitReceving.setVisibility(View.GONE);

        }else {
            customAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待收货");;
            customAwaitReceingViewHolder.mRlFootCustomAwaitReceving.setVisibility(View.VISIBLE);
        }
        customAwaitReceingViewHolder.mTvExpresstitleCustomAwaitReceving.setText(""+acceptStation);
        customAwaitReceingViewHolder.mTvExpressTimeCustomAwaitReceving.setText(""+acceptTime);

     //   customAwaitReceingViewHolder.mTvPricestateItemOrderHead.setText("等待收货");
        Glide.with(mContext).load(goodsList.get(0).getListUrl()).into(customAwaitReceingViewHolder.mIvGoodsiconCustomForPricing);
        customAwaitReceingViewHolder.mTvMessgeCustomForPricing.setText(storeListBean.getMsg() + "");
        customAwaitReceingViewHolder.mTvGoodsnumberCustomAwaitReceving.setText("共" + storeListBean.getNum() + "件商品  实付款:");
        customAwaitReceingViewHolder.mTvAwaitpayforCustomAwaitReceving.setText("￥"+ UIUtils.getMoney( storeListBean.getActualPrice()));
        customAwaitReceingViewHolder.mLlStorerootItemOrderHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
            }
        });

        customAwaitReceingViewHolder.mLlCustomconetRootLayoutOrderCustomConttent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);

            }
        });

        /**确定收货*/
        customAwaitReceingViewHolder.mTvSurerecevingCustomAwaitReceving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //
              //  ToastUtils.makeText("确定收货");
               // LogUtils.i(TAG,"确定收货");
                showGotGoodsDialog(position,"您是否已收到该订单商品？","未收货","已收货", Contans.SURE_ACCEPT_GOODS_TYPE);

            }
        });
        customAwaitReceingViewHolder.mTvCheckExpressCustomAwaitReceving.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看物流
              //  ToastUtils.makeText("查看物流");
                LogUtils.i(TAG,"查看物流");
                ExpressActivity.startActivity(mContext,storeListBean.getOrderDetailId());
            }
        });

    }
}
